package de.lulusoft.anothertorrent.core.rtorrent;

import java.util.ArrayList;
import java.util.Iterator;

public class TorrentArrayList extends ArrayList<Torrent> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7714158472740686509L;

	@Override
	public boolean contains(Object o) {
		if (o instanceof Torrent)
		{
			
			Torrent torrent = (Torrent)o;
			Iterator<Torrent> it = this.iterator();
			while (it.hasNext())
			{
				Torrent t = it.next();
				if (t.getHash().equals(torrent.getHash()))
					return true;
			}
			return false;
		}
		else
			return super.contains(o);
	}
	
	public Torrent getByHash(String hash)
	{
		Iterator<Torrent> it = this.iterator();
		while (it.hasNext())
		{
			Torrent t = it.next();
			if (t.getHash().equals(hash))
				return t;
		}
		return null;
	}
	
	

}
